home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / yinyang < prev   
Encoding:
Text File  |  2001-04-23  |  5.3 KB  |  188 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5. #
  6. # Gimp yin/yang symbol plugin for The Gimp. Extract documentation by running
  7. # "perldoc" on this plugin, or by using the pod utilities (pod2man, pod2html,
  8. # etc.)
  9. #
  10. # Written by Aaron Sherman, (c) 1998
  11. #   04-22-2001, peter@kirchgessner.net: fix problems with functions
  12. #               that changed number of arguments
  13.  
  14. use Gimp qw(:auto __ N_);
  15. use Gimp::Fu;
  16.  
  17. # Main function. Takes width, height, do_eyes (toggle), eye_images (toggle),
  18. # white_eye_image (filename) and black_eye_image (filename).
  19. # Creates a stand-alone image with a yin-yang symbol in black and white.
  20. sub yinyang {
  21.     my $width = shift;
  22.     my $height = shift;
  23.     my $do_eyes = shift;
  24.     my $eye_images = shift;
  25.     my $white_eye_image = shift;
  26.     my $black_eye_image = shift;
  27.     my $aa = shift;
  28.  
  29.     # Create new image
  30.     my $img = gimp_image_new($width,$height,0);
  31.     my $layer = gimp_layer_new($img,$width,$height,1,"Yin/Yang",100,0);
  32.     gimp_image_add_layer($img,$layer,0);
  33.     gimp_image_set_active_layer($img,$layer);
  34.     my $draw = gimp_image_active_drawable($img);
  35.     my $oldcolor = gimp_palette_get_foreground();
  36.     gimp_palette_set_foreground([0,0,0]);
  37.     gimp_selection_all($img);
  38.     gimp_bucket_fill($draw,0,0,100,0,0,0,0);
  39.  
  40.     # Create the yin-yang shape
  41.     #gimp_selection_invert($img);
  42.     gimp_selection_none($img);
  43.     gimp_rect_select($img,0,0,$width/2,$height,0,0,0);
  44.     gimp_ellipse_select($img,$width/2-$width/4,0,$width/2,
  45.             int($height/2),0,$aa,0,0);
  46.     gimp_ellipse_select($img,$width/2-$width/4,$height/2,
  47.             $width/2, $height/2, 1, $aa, 0, 0);
  48.     gimp_palette_set_foreground([255,255,255]);
  49.     gimp_bucket_fill($draw,0,0,100,0,0,0,0);
  50.  
  51.     # Cut away all but the central circle
  52.     gimp_ellipse_select($img,0,0,$width,$height,2,$aa,0,0);
  53.     gimp_selection_invert($img);
  54.     gimp_edit_clear($draw);
  55.  
  56.     # Create the "eyes"
  57.     if ($do_eyes) {
  58.     my $x1 = $width/2-$width/16;
  59.     my $y1 = $height/2-$height/4-$height/16;
  60.     my $x2 = $x1;
  61.     my $y2 = $height/2+$height/4-$height/16;
  62.     my $eyewidth = $width/8;
  63.     my $eyeheight = $height/8;
  64.     insert_eye($img,$eye_images,$white_eye_image,[0,0,0],$x1,$y1,$eyewidth,
  65.            $eyeheight,$draw,$aa);
  66.     insert_eye($img,$eye_images,$black_eye_image,[255,255,255],$x2,$y2,
  67.            $eyewidth,$eyeheight,$draw,$aa);
  68.     }
  69.  
  70.     # Finish up
  71.     gimp_palette_set_foreground($oldcolor);
  72.     gimp_selection_none($img);
  73.  
  74.     $img;
  75. }
  76.  
  77. # This subroutine inserts an "eye" (a dot in the center of the cicular
  78. # part of each of the halves of the yin-yang). The eye is either
  79. # a solid dot of the opposite color from that half of the yin-yang or
  80. # an image, which is loaded and scaled to fit.
  81. sub insert_eye {
  82.     my $img = shift;
  83.     my $do_image = shift;
  84.     my $file = shift;
  85.     my $color = shift;
  86.     my $x = shift;
  87.     my $y = shift;
  88.     my $width = shift;
  89.     my $height = shift;
  90.     my $draw = shift;
  91.     my $aa = shift;
  92.  
  93.     gimp_ellipse_select($img,$x,$y,$width,$height,2,$aa,0,0);
  94.     gimp_palette_set_foreground($color);
  95.     if ($do_image) {
  96.     my $eye = gimp_file_load(NON_INTERACTIVE,$file,$file);
  97.     gimp_image_scale($eye,$width,$height);
  98.     gimp_selection_all($eye);
  99.     my $eyedraw = gimp_image_active_drawable($eye);
  100.     gimp_edit_copy($eyedraw);
  101.     my $float = gimp_edit_paste($draw,1);
  102.     gimp_floating_sel_anchor($float);
  103.     gimp_image_delete($eye);
  104.     } else {
  105.     gimp_bucket_fill($draw,0,0,100,0,0,0,0);
  106.     }
  107. }
  108.  
  109. # Register with The Gimp
  110. register("yinyang", "Render a stand-alone Yin/Yang image",
  111.     "Renders a black-and-white Yin/Yang symbol optionally
  112.     with \"eyes\" that may optionally be images.",
  113.     "Aaron Sherman", "(c) 1998, Aaron Sherman",
  114.     "1999b", N_"<Toolbox>/Xtns/Render/Yin-Yang...", undef,
  115.     [
  116.         [PF_INT32, "width", "Width", 256],
  117.         [PF_INT32, "height", "Height", 256],
  118.         [PF_TOGGLE, "insert_eyes", "", 1],
  119.         [PF_TOGGLE, "eyes_are_images", "", 0],
  120.         [PF_STRING, "top_eye_filename", "eye 1", ""],
  121.         [PF_STRING, "bottom_eye_filename", "eye 2", ""],
  122.         [PF_TOGGLE, "anti_aliasing", "", 1]
  123.     ],
  124.         [PF_IMAGE],
  125.     \&yinyang);
  126.  
  127. exit main;
  128.  
  129. __END__
  130.  
  131. =head1 NAME
  132.  
  133. yinyang
  134.  
  135. =head1 SYNOPSIS
  136.  
  137. yinyang
  138.  
  139. =head1 DESCRIPTION
  140.  
  141. B<yinyang> is a B<Gimp> plugin. It generates a Yin/Yang symbol, which
  142. is a Chinese symbol of duality. It takes as parameters (provided by the
  143. Gimp user interface) the width and height of the resulting image;
  144. a toggle to indicate if "eyes" should be inserted (see I<EYES>);
  145. a toggle to indicate if the eyes should be images that are
  146. loaded separately; the two filenames for the eyes and a toggle to
  147. indicate if anti-aliasing should be used.
  148.  
  149. =head1 EYES
  150.  
  151. The "eyes" are normally either black or white dots in the middle of the
  152. circular regions of the two halves of the Yin and Yang. If you like
  153. you can load these eyes from another image.
  154.  
  155. =head1 IDEAS
  156.  
  157. Here are some thoughts on how the plugin could be used:
  158.  
  159. =over 5
  160.  
  161. =item *
  162.  
  163. Use as a low-opacity layer over an image to indicate duality or harmony.
  164.  
  165. =item *
  166.  
  167. Use to replace circular objects in an image (e.g. eyes, street signs,
  168. the sun, etc.)
  169.  
  170. =item *
  171.  
  172. Map two opposed or dualistic images. One into the black region, one
  173. into the white. For a really cool look, make the eyes show a peice of
  174. the other image.
  175.  
  176. =item *
  177.  
  178. Dip in 1 tbsp chunky peanut butter, 1 tbsp rice vinegar, 1 tbsp
  179. lime juice, 1 dash black pepper. Eat to taste.
  180.  
  181. =back
  182.  
  183. =head1 AUTHOR
  184.  
  185. Written by Aaron Sherman <ajs@ajs.com>, (c) 1998.
  186.  
  187. =cut
  188.